# https://console.bce.baidu.com/qianfan/ais/console/onlineService  应用服务：Stable-Diffusion-XL
import requests
import json
import base64


def get_access_token():
    """
    使用 API Key，Secret Key 获取access_token，替换下列示例中的应用API Key、应用Secret Key
    """

    url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=USWFVH0OWPU610gW4LEUCy7G&client_secret=UxO7GVplODUieGMfUhmbNKu2CCQ8MdnN"

    payload = json.dumps("")
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }

    response = requests.request("POST", url, headers=headers, data=payload)
    return response.json().get("access_token")


def main():
    # url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/text2image/sd_xl?access_token=" + get_access_token()
    url = "https://aip.baidubce.com/rest/2.0/wenxinworkshop/api/v1/template/info?access_token=24.63252a0845e7c2d48f9796e4c6ee0f72.2592000.1703907325.282335-44024207&id=10556"

    payload = json.dumps("")
    headers = {
        'Content-Type': 'application/json'
    }

    response = requests.request("GET", url, headers=headers, data=payload).text

    print(response)


if __name__ == '__main__':
    main()
